


<template>
  <div class="wrapper">
    <!-- header部分 -->
    <header>
      <p>用户登陆</p>
    </header>

    <!-- 表单部分 -->
    <ul class="form-box">
      <li>
        <div class="title">
          账号：
        </div>
        <div class="content">
<!--            <p>账号</p><input type="text" v-model="userId">
            <p>旧密码</p><input type="password" v-model="userPwd">
            <p>新密码</p><input type="password" v-model="userNewPwd">
            <button @click="updatePwd">修改</button>
            <p>{{resInf}}</p>-->
          <input type="text" placeholder="账户" v-model="userId">
<!--            <input type="text" placeholder="密码" v-model="password">-->

        </div>
      </li>
      <li>
        <div class="title">
          密码：
        </div>
        <div class="content">
<!--          <input type="password" placeholder="密码">-->
            <input type="text" placeholder="密码" v-model="password">
<!--            <p>{{resInf}}</p>-->
        </div>
      </li>
    </ul>

<!--    <div class="button-login">
      <button>登陆</button>
    </div>-->
      <div class="button-login">
       <button @click="updatePwd">登录</button>
      </div>
    <div class="button-register">
      <button>去注册</button>
    </div>
  </div>
</template>

<script setup>
import {ref,inject} from "vue";
import axios from "axios";
import router from "../router/index.js";
const $http = inject("$axios");
const $queryStr=inject("$qs")
const password=ref("");
const userId=ref("");
const userPwd=ref("");
const userNewPwd=ref("");
const resInf=ref("");
const businessId=ref()

function updatePwd(){
    $http.post(`/api/elm_api/UserController/login`,
        $queryStr.stringify({
            userId:userId.value,
            password:password.value
        })
    ).then(res=>{
        if(res.data!=null){
            localStorage.setItem('access-admin',JSON.stringify(res.data))
        }
    })
    $http.post(`/api/elm_api/UserController/getUserByIdByPass`,
      $queryStr.stringify({
        userId:userId.value,
        password:password.value
        })
    ).then(res=>{
            let response=res.data/*.businessName*/;
/*            alert(response.userName)*/
        if(response.userName==="张三丰"&&response.password==="123"){
            alert("登陆成功，你的角色为：顾客")
/*            alert(response)
            alert(response.userName)*/
            router.push({name:'Index'})
        }else {
            alert("登陆失败")
        }
    });
}
function handleClick(Num){
    //路由负责跳转
    if (Num===1)router.push('/Index')
    if(Num===2)router.push('/OrderList')
    if(Num===3)router.push('/Login')

}

</script>

<style scoped lang="css">
@import "../../src/css/login.css";
@import "../../src/css/font-awesome/css/font-awesome.min.css";
@import "../../src/css/normalize.css";
</style>